const app = getApp();
const moment = require('../../../utils/moment/index.js');
Component({
    properties:{
        goodsList:{
            type:Object,
            value:null,
            observer:"changeGoods"
        }
    },
    data:{
        imageUrl:"",
        goods:null,
        buyMembers:[],
        specially:"#00CC66",//主题色
        },
        attached(){
            this.setData({
              specially:app.theme.specially
            })
          },
    methods:{
        changeGoods(newVal){
            if(Object.keys(newVal).length !== 0) {
                let buyLogsRes = [];
                if (newVal.buyLogs) {
                    //过滤无效数据
                    const start = moment(newVal.timestart).utc();
                    let buyLogs = newVal.buyLogs.filter(item => {
                        item.buyTime = app.functions.dateFormat(item.createTime,'MM-DD HH:mm');
                        return moment(item.createTime) >= start;
                    });
                    buyLogsRes = buyLogs || [];
                }
                newVal.timestart = app.functions.dateTimeFormat(newVal.timestart);
                newVal.timeend = app.functions.dateTimeFormat(newVal.timeend);
                newVal.pickupTime = app.functions.dateTimeFormat(app.functions.pickupTime(newVal));
               this.setData({
                buyMembers: buyLogsRes,
                goods:newVal,
                imageUrl:app.functions.convertImageUrl(newVal.thumbSquare || newVal.thumb)
               }) 
            }
        }
    }
})